//js与数据库的交互，将在控制器中被使用
const connection = require("../app/database");

class UserService {
  //创建用户
  async create(user) {
    const { name, password } = user;
    const statement = `INSERT INTO users (name, password) VALUES (?, ?);`;

    const result = await connection.execute(statement, [name, password]);

    //将user存储到数据库中
    return result;
  }
  //查询用户名是否被注册
  async getUserByName(name) {
    const statement = `SELECT * FROM users WHERE name = ?;`;
    const result = await connection.execute(statement, [name]);

    return result[0];
  }
}

module.exports = new UserService();
